The Operating System automatically initializes your application's heap when your application is launched. To help prevent heap fragmentation, you should call the procedures in this section before you allocate any blocks of memory in your heap.
Use the MaxApplZone procedure to extend the application heap zone to the application heap limit so that the Memory Manager does not do so gradually as memory requests require. Use the MoreMasters procedure to preallocate enough blocks of master pointers so that the Memory Manager never needs to allocate new master pointer blocks for you.
To help ensure that you can use as much of the application heap zone as possible, call the MaxApplZone procedure. Call this once near the beginning of your program, after you have expanded your stack.
PROCEDURE MaxApplZone;
The MaxApplZone procedure expands the application heap zone to the application heap limit. If you do not call MaxApplZone , the application heap zone grows as necessary to fulfill memory requests. The MaxApplZone procedure does not purge any blocks currently in the zone. If the zone already extends to the limit, MaxApplZone does nothing.
It is a good idea to call MaxApplZone once at the beginning of your program if you intend to maintain an effectively partitioned heap. If you do not call MaxApplZone and then call MoveHHi to move relocatable blocks to the top of the heap zone before locking them, the heap zone could later grow beyond these locked blocks to fulfill a memory request. If the Memory Manager were to allocate a nonrelocatable block in this new space, your heap would be fragmented.
Call the MoreMasters procedure several times at the beginning of your program to prevent the Memory Manager from running out of master pointers in the middle of application execution. If it does run out, it allocates more, possibly causing heap fragmentation.
PROCEDURE MoreMasters;
The MoreMasters procedure allocates another block of master pointers in the current heap zone. In the application heap, a block of master pointers consists of 64 master pointers, and in the system heap, a block consists of 32 master pointers. (These values, however, might change in future versions of system software.) When you initialize additional heap zones, you can specify the number of master pointers you want to have in a block of master pointers.
The Memory Manager automatically calls MoreMasters once for every new heap zone, including the application heap zone.
You should call MoreMasters at the beginning of your program enough times to ensure that the Memory Manager never needs to call it for you. For example, if your application never allocates more than 300 relocatable blocks in its heap zone, then five calls to the MoreMasters should be enough. It's better to call MoreMasters too many times than too few. For instance, if your application usually allocates about 100 relocatable blocks but might allocate 1000 in a particularly busy session, call MoreMasters enough times at the beginning of the program to accommodate times of greater memory use.
If you are forced to call MoreMasters so many times that it causes a significant slowdown, you could change the moreMast field of the zone header to the total number of master pointers you need and then call MoreMasters just once. Afterward, be sure to restore the moreMast field to its original value.
Because MoreMasters allocates memory, you should not call it at interrupt time.
The calls to MoreMasters at the beginning of your application should be in the main code segment of your application or in a segment that the main segment never unloads.
If you initialize a new zone, you can specify the number of master pointers that a master pointer block should contain. See the description of the InitZone procedure on InitZone for details.